package com.maodou.android.ui.navigation

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.navigation3.runtime.NavEntry
import com.maodou.android.ui.page.AccountDetailKey
import com.maodou.android.ui.page.AppRouteKey
import com.maodou.android.ui.page.CategoryKey
import com.maodou.android.ui.page.ContactKey
import com.maodou.android.ui.page.MainKey
import com.maodou.android.ui.page.DetailKey
import com.maodou.android.ui.page.EditAccountKey
import com.maodou.android.ui.page.ForgotKey
import com.maodou.android.ui.page.ImportKey
import com.maodou.android.ui.page.LoginKey
import com.maodou.android.ui.page.RegisterKey
import com.maodou.android.ui.page.SearchKey
import com.maodou.android.ui.page.SplashKey
import com.maodou.android.ui.page.Verify2faKey
import com.maodou.android.ui.page.WebViewKey
import com.maodou.android.ui.page.account.AccountDetailsScreen
import com.maodou.android.ui.page.account.CategoryListScreen
import com.maodou.android.ui.page.account.EditAccountScreen
import com.maodou.android.ui.page.account.ImportAccountScreen
import com.maodou.android.ui.page.account.Verify2faScreen
import com.maodou.android.ui.page.detail.DetailScreen
import com.maodou.android.ui.page.login.ForgotScreen
import com.maodou.android.ui.page.login.LoginScreen
import com.maodou.android.ui.page.login.RegisterScreen
import com.maodou.android.ui.page.main.MainScreen
import com.maodou.android.ui.page.search.SearchScreen
import com.maodou.android.ui.page.setting.ContactUsScreen
import com.maodou.android.ui.page.splash.SplashScreen
import com.maodou.android.ui.page.web.WebViewScreen

/**
 * 路由注册管理器
 * 统一管理所有页面的路由映射关系
 */
object RouteRegistry {
    
    /**
     * 根据路由键创建对应的 NavEntry
     * 新增页面时，只需要在这里添加对应的映射关系即可
     */
    fun createNavEntry(route: AppRouteKey): NavEntry<AppRouteKey> {
        return when (route) {
            is SplashKey -> NavEntry(route) { SplashScreen() }
            is LoginKey -> NavEntry(route) { LoginScreen() }
            is RegisterKey -> NavEntry(route) { RegisterScreen() }
            is ForgotKey -> NavEntry(route) { ForgotScreen() }
            is MainKey -> NavEntry(route) { MainScreen() }
            is DetailKey -> NavEntry(route) { DetailScreen(route) }
            is SearchKey -> NavEntry(route) { SearchScreen() }
            is EditAccountKey -> NavEntry(route) { EditAccountScreen(route) }
            is ImportKey -> NavEntry(route) { ImportAccountScreen() }
            is CategoryKey -> NavEntry(route) { CategoryListScreen() }
            is Verify2faKey -> NavEntry(route) { Verify2faScreen(route) }
            is ContactKey -> NavEntry(route) { ContactUsScreen() }
            is AccountDetailKey -> NavEntry(route) { AccountDetailsScreen(route) }
            is WebViewKey -> NavEntry(route) { WebViewScreen(route) }
            else -> NavEntry(route) { UnknownRouteScreen(route) }
        }
    }
    
    /**
     * 未知路由的默认页面
     */
    @Composable
    private fun UnknownRouteScreen(route: AppRouteKey) {
        Text("Unknown route: $route")
    }
}